<?php

  define('BASE_ROOT_PATH', dirname(dirname(__FILE__)));
	include_once( BASE_ROOT_PATH . "/word/db/DBMySQL.php");  

	$memberId = $_REQUEST['id'];
	if(empty($memberId)) {
	  $msg = json_encode("用户id不能为空");
		echo '{"code":"1","msg":'.$msg.'}';
		exit();
	}

	$token= $_REQUEST['token'];
	if(empty($token)) {
	  $msg = json_encode("Apple Push Notification Token不能为空");
		echo '{"code":"1","msg":'.$msg.'}';
		exit();
	}
	// 查找用户
	$db = new DBMySQL();
	$rs = $db->Query("select m.member_id from t_member where m.member_id = $memberId limit 1");
	if(empty($rs)) {
	  $msg = json_encode("该用户不存在");
		echo '{"code":"1","msg":'.$msg.'}';
		exit();
	}
	
	$db->Modify("replace into t_token(member_id,token) values($memberId,'$token')");	
	
	
	echo '{"code":"0","msg":""}';
	//echo "replace into t_token(member_id,token) values($memberId,$token)";
	
?>